<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <div>11</div>

    <script>

        // cssText 

        var oDiv = document.querySelector('div');
        setCss(oDiv, {
            color: 'red',
            fontSize: '20px',
            background: 'yellow'
        })

        function setCss(ele, obj) {
            // 遍历对象
            // oDiv.style.color = 'red' ;
            // oDiv.style.fontSize = "20px";

            for (var prop in obj) {
                ele.style[prop] = obj[prop];
            }
        }

    </script>

</body>

</html>